//
//  MHLoginController.m
//  M-Saler
//
//  Created by Teresa on 2020/5/21.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "MHLoginController.h"
#import "MHLoginRequest.h"
#import "MHUserModel.h"


@interface MHLoginController ()
@property (weak, nonatomic) IBOutlet UITextField *shopNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextField;

@end

@implementation MHLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}


#pragma mark - Action

- (IBAction)closePage:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)loginBtnClicked:(UIButton *)sender {
    [self.view endEditing:YES];
    MHLoginRequest *req = [MHLoginRequest new];
    req.shop_sn = self.shopNameTextField.text;
    req.username = self.userNameTextField.text;
    req.password = self.pwdTextField.text;
    WEAKSELF;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        MHUserModel *userModel = response.data;
        [userModel save];
        [weakSelf dismissViewControllerAnimated:YES completion:^{
            DLog(@"%@",weakSelf.presentingViewController);
        }];
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance]tipMessage:response.message];
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

@end
